******************************************
** Replication Data 
** Betz, Tariff Evasion and Trade Policies 
** International Studies Quarterly
******************************************

clear all

** load data
set more off
use "Betz_ISQ_country-year.dta", replace
xtset iso3n year


** Table 1
global controls "lngdp gdp_capita i.year"

glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg sd_ahs_c burqual_ic_norm $controls mean_ahs_c, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  se(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )


** Figure 1 
graph drop _all
qui{
qui glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
capture drop lower1 upper1 effect1 axis1 include1
gen include1 = e(sample)
gen axis1 = .
gen lower1 = .
gen upper1 = .
gen effect1 = .
local i = 0
qui while `i' < 11 {
local a = `i'/10
margins, at(burqual_ic_norm = `a')
matrix coef = r(b)
matrix var = r(V)
scalar b = coef[1,1]
scalar sde = var[1,1]
scalar sde = sqrt(sde)
replace axis1 = `a' if _n == `i' + 1
replace effect1 = b if _n == `i' + 1
replace lower1 = b - 1.96*sde if _n == `i' + 1
replace upper1 = b + 1.96*sde if _n == `i' + 1
local i = `i' + 1
}
graph drop _all
qui su level_share if include == 1
local avg_share = r(mean)
#delimit ;
twoway histogram burqual_ic_norm if include == 1, discrete percent yaxis(1) lcolor(gs6) yscale(alt axis(2)) fintensity(inten20) fcolor(gs12)
  || line lower axis1, color(gs6) lcolor(gs8) lwidth(thick) lpattern(dash) yaxis(2)  yscale(alt axis(1))
  || line upper axis1, color(gs6) lcolor(gs8) lwidth(thick) lpattern(dash) yaxis(2) yscale(alt axis(1))
  || line effect axis1, color(gs2) lcolor(gs8) lwidth(vthick) lpattern(solid)
  yline(0, lstyle(foreground) axis(2)) 
  yline(`avg_share', lstyle(foreground) lpattern(dash) axis(2))
  yaxis(2, )  yscale(alt axis(1))
  ylabel(0(.5)1, axis(2) labsize(vlarge))
  yscale(r(0(25)75) axis(1))
  ylabel(none, axis(1))
  xlabel(none)
  ytitle("Capacity", axis(2) size(vlarge)) 
  ytitle("", axis(1)) 
  xtitle("")
  msize(*2.5)
  legend(off)
  scheme(lean1) plotregion(style(none)) 
  xsize(4)
  ysize(3)
  subtitle("Uniform", size(huge) ring(0) )
  name(ic_share) nodraw
 ;
#delimit cr



qui glm peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
capture drop lower1 upper1 effect1 axis1 include1
gen include1 = e(sample)
gen axis1 = .
gen lower1 = .
gen upper1 = .
gen effect1 = .
local i = 0
qui while `i' < 11 {
local a = `i'/10
margins, at(burqual_ic_norm = `a')
matrix coef = r(b)
matrix var = r(V)
scalar b = coef[1,1]
scalar sde = var[1,1]
scalar sde = sqrt(sde)
replace axis1 = `a' if _n == `i' + 1
replace effect1 = b if _n == `i' + 1
replace lower1 = b - 1.96*sde if _n == `i' + 1
replace upper1 = b + 1.96*sde if _n == `i' + 1
local i = `i' + 1
}

qui su peak_share if include == 1
local avg_share = r(mean)
#delimit ;
twoway histogram burqual_ic_norm if include == 1, discrete percent yaxis(1) lcolor(gs6) yscale(alt axis(2)) fintensity(inten20) fcolor(gs12)
  || line lower axis1, lcolor(gs8) lwidth(thick) lpattern(dash) yaxis(2)  yscale(alt axis(1))
  || line upper axis1, lcolor(gs8) lwidth(thick) lpattern(dash) yaxis(2) yscale(alt axis(1))
  || line effect axis1, color(gs2) lcolor(gs8) lwidth(vthick)  lpattern(solid)
  yline(0, lstyle(foreground) axis(2)) 
  yline(`avg_share', lstyle(foreground) lpattern(dash) axis(2))
  yaxis(2)  yscale(alt axis(1))
  ylabel(0(.25).5, axis(2) labsize(vlarge))
  yscale(r(0(25)75) axis(1))
  ylabel(none, axis(1))
  xlabel(none)
  ytitle("", axis(2)) 
  ytitle("", axis(1)) 
  xtitle("")
  msize(*2.5)
  legend(off)
  scheme(lean1) plotregion(style(none)) 
  xsize(4)
  ysize(3)
  subtitle("Peaks", size(huge) ring(0))
  name(ic_peak) nodraw
 ;
#delimit cr


qui glm cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
capture drop lower1 upper1 effect1 axis1 include1
gen include1 = e(sample)
gen axis1 = .
gen lower1 = .
gen upper1 = .
gen effect1 = .
local i = 0
qui while `i' < 11 {
local a = `i'/10
margins, at(burqual_ic_norm = `a')
matrix coef = r(b)
matrix var = r(V)
scalar b = coef[1,1]
scalar sde = var[1,1]
scalar sde = sqrt(sde)
replace axis1 = `a' if _n == `i' + 1
replace effect1 = b if _n == `i' + 1
replace lower1 = b - 1.96*sde if _n == `i' + 1
replace upper1 = b + 1.96*sde if _n == `i' + 1
local i = `i' + 1
}

qui su cut_share if include == 1
local avg_share = r(mean)
#delimit ;
twoway histogram burqual_ic_norm if include == 1, discrete percent yaxis(1) lcolor(gs6) yscale(alt axis(2)) fintensity(inten20) fcolor(gs12)
  || line lower axis1, lcolor(gs8) lwidth(thick) lpattern(dash) yaxis(2)  yscale(alt axis(1))
  || line upper axis1, lcolor(gs8) lwidth(thick) lpattern(dash) yaxis(2) yscale(alt axis(1))
  || line effect axis1, color(gs2) lcolor(gs8) lwidth(vthick)  lpattern(solid)
  yline(0, lstyle(foreground) axis(2)) 
  yline(`avg_share', lstyle(foreground) lpattern(dash) axis(2))
  yaxis(2)  yscale(alt axis(1))
  ylabel(0(.25).5, axis(2) labsize(vlarge))
  yscale(r(0(25)75) axis(1))
  ylabel(none, axis(1))
  xlabel(none)
  ytitle("", axis(2)) 
  ytitle("", axis(1)) 
  xtitle("")
  msize(*2.5)
  legend(off)
  scheme(lean1) plotregion(style(none)) 
  xsize(4)
  ysize(3)
  subtitle("Cuts", size(huge) ring(0))
  name(ic_zero) nodraw
 ;
#delimit cr




}

*
#delimit ;
graph combine ic_share ic_peak ic_zero  ,  
col(3) iscale(1) imargin(0)
ysize(2) xsize(6.5)
scheme(lean1)
;
# delimit cr

graph export "Figure1.eps", as(eps) replace
graph export "Figure1.pdf", as(pdf) replace


** Figure 2
do "Betz_ISQ_cases.do"


** Table 2 
global controls "lngdp gdp_capita democ vdem_gcrrpt i.year"
global controls2 "lngdp gdp_capita democ vdem_gcrrpt lnexports fdioutpgdp naturalresource manufacturing hh_cimport i.year"

glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

glm level_share burqual_ic_norm $controls2 , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m4

glm peak_share burqual_ic_norm $controls2 , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m5

glm cut_share burqual_ic_norm $controls2 , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m6

estout m1 m2 m3 m4 m5 m6 , extracols(4) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  se(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries")) ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  democ "Democracy" vdem_gcrrpt "Legislative corruption" ///
  naturalresources "Natural resources" lnexports "Exports" lnpop "Population" naturalresource "Natural resources" ///   
  manufacturing "Manufacturing" fdioutpgdp "FDI" share_anyimp "Import penetration" hh_cimport "HHI imports" _cons "Constant" )

  
  
********************************************
** Appendix 
********************************************

* histograms
capture graph drop h1 h2 h3
hist level_share, name(h1) subtitle("Uniform tariffs", ring(1) box width(140) size(huge)) scheme(lean1) percent xtitle("") 
graph export "histogram_1.pdf", as(pdf) replace
hist peak_share, name(h2) subtitle("Tariff peaks", ring(1) box width(140) size(huge)) scheme(lean1) percent  xtitle("") 
graph export "histogram_2.pdf", as(pdf) replace
hist cut_share, name(h3) subtitle("Selective cuts", ring(1) box width(140) size(huge)) scheme(lean1) xtitle("") percent 
graph export "histogram_3.pdf", as(pdf) replace


* summary statistics
glm level_share burqual_ic_norm lngdp gdp_capita , nolog link(logit) family(binomial) robust cluster(iso3n)
gen sample1 = e(sample)

sutex level_share peak_share cut_share burqual_ic_norm lngdp gdp_capita democ vdem_gcrrpt lntrade fdioutpgdp naturalresource manufacturing hh_cimport if sample1 == 1, minmax digits(3) labels


* alternative measures capacity
global controls "lngdp gdp_capita i.year"

glm level_share bureaufac_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share bureaufac_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share bureaufac_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg sd_ahs_c bureaufac_norm $controls mean_ahs_c, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(bureaufac_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" bureaufac_norm "Bureaucratic Capacity (Factor)" ///
  mean_ahs_c "Average tariff" _cons "Constant" )

glm level_share stat_capacity_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share stat_capacity_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share stat_capacity_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg sd_ahs_c stat_capacity_norm $controls mean_ahs_c , robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(stat_capacity_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" stat_capacity_norm "Statistical Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )

glm level_share e_wbgi_gee_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share e_wbgi_gee_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share e_wbgi_gee_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg sd_ahs_c e_wbgi_gee_norm $controls mean_ahs_c, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(e_wbgi_gee_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" e_wbgi_gee_norm "Government effectiveness" ///
  mean_ahs_c "Average tariff" _cons "Constant" )


* imputed tariff data
global controls "lngdp gdp_capita i.year"

glm imputed_level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm imputed_peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm imputed_cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg imputed_sd_ahs_c burqual_ic_norm $controls imputed_mean_ahs_c, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )

  
* MFN applied tariffs
global controls "lngdp gdp_capita i.year"

glm level_share_mfn burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share_mfn burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share_mfn burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg sd_mfn_c burqual_ic_norm $controls mean_mfn_c, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  c_mean_mfn "Average tariff" _cons "Constant" )

  
* product-level
preserve
use "country-year-hs4.dta", replace

set matsize 4000
set more off
global controls "lngdp gdp_capita i.year"

egen group = group(hs4)
gen double iso3nhs4 = iso3n*10000 + group

logit level burqual_ic_norm $controls , nolog robust cluster(iso3nhs4)
estimates store m1

logit level burqual_ic_norm $controls i.group , nolog robust cluster(iso3nhs4)
estimates store m2

logit dummy burqual_ic_norm $controls , nolog robust cluster(iso3nhs4)
estimates store m3

logit dummy burqual_ic_norm $controls i.group, nolog robust cluster(iso3nhs4)
estimates store m4

logit some_zero burqual_ic_norm $controls , nolog robust cluster(iso3nhs4)
estimates store m5

logit some_zero burqual_ic_norm $controls i.group, nolog robust cluster(iso3nhs4)
estimates store m6

estout m1 m2 m3 m4 m5 m6, extracols(3 5) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year *group) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )
restore 


* below HS6
set more off
global controls "lngdp gdp_capita i.year"

glm level_share_hs6 burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1
glm peak_share_hs6 burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2
glm cut_share_hs6 burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3
reg avg_sd_below_hs6  burqual_ic_norm $controls mean_ahs_c , robust cluster(iso3n)  
estimates store m4
nbreg totallines burqual_ic_norm $controls , nolog robust cluster(iso3n)  
estimates store m5

estout m1 m2 m3 m4 m5, extracols(4) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )

  

* Number product groups
glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1
glm peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimate store m2 
glm cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3
reg sd_ahs_c burqual_ic_norm $controls mean_ahs_c, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(ln_number_hs4 "Number HS4 categories" lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )
  

* weighted regression
global controls "lngdp gdp_capita i.year"

glm level_share burqual_ic_norm $controls [aweight=1/ln_c_obs], nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1
glm peak_share burqual_ic_norm $controls [aweight=1/ln_c_obs], nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2
glm cut_share burqual_ic_norm $controls [aweight=1/ln_c_obs], nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3
reg sd_ahs_c burqual_ic_norm $controls [aweight=1/ln_c_obs], robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )
 

* alternative estimators
global controls "lngdp gdp_capita i.year"

glm level_share burqual_ic_norm $controls , nolog family(binomial) link(probit) robust cluster(iso3n)
estimates store m1

reg level_share burqual_ic_norm $controls , robust cluster(iso3n)
estimates store m2

glm peak_share burqual_ic_norm $controls , nolog family(binomial) link(probit) robust cluster(iso3n)
estimates store m3

reg peak_share burqual_ic_norm $controls , robust cluster(iso3n)
estimates store m4

glm cut_share burqual_ic_norm $controls , nolog family(binomial) link(probit) robust cluster(iso3n)
estimates store m5

reg cut_share burqual_ic_norm $controls , robust cluster(iso3n)
estimates store m6

estout m1 m2 m3 m4 m5 m6, extracols(3 5) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  _cons "Constant" )
  
  
* just econ controls
global controls "lngdp gdp_capita lnexports fdioutpgdp naturalresource manufacturing hh_cimport i.year"
global controls2 "l.(lngdp gdp_capita lnexports fdioutpgdp naturalresource manufacturing hh_cimport) i.year"

glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

glm level_share burqual_ic_norm $controls2 , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m4

glm peak_share burqual_ic_norm $controls2 , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m5

glm cut_share burqual_ic_norm $controls2 , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m6

estout m1 m2 m3 m4 m5 m6 , extracols(4) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries")) ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  lnexports "Exports" lnpop "Population" naturalresources "Natural resources" ///   
  manufacturing "Manufacturing" fdioutpgdp "FDI" hh_cimport "HHI imports" _cons "Constant" ///
  L.lngdp "GDP" L.gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  L.naturalresources "Natural resources" L.lnexports "Exports" L.lnpop "Population" ///   
  L.manufacturing "Manufacturing" L.fdioutpgdp "FDI" L.hh_cimport "HHI imports" _cons "Constant")

  
* instrument for trade
ivregress 2sls level_share burqual_ic_norm (lntrade = wto_members) lngdp gdp_capita , robust cluster(iso3n)  first
estimates store m1

ivregress 2sls peak_share burqual_ic_norm (lntrade = wto_members) lngdp gdp_capita , robust cluster(iso3n)  first
estimates store m2

ivregress 2sls cut_share burqual_ic_norm (lntrade = wto_members) lngdp gdp_capita , robust cluster(iso3n)  first
estimates store m3

ivregress 2sls sd_ahs_c burqual_ic_norm (lntrade = wto_members) mean_ahs_c lngdp gdp_capita , robust cluster(iso3n)  first
estimates store m4
  
estout m1 m2 m3 m4, extracols(4) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )


* drop products without recorded trading activity
global controls "lngdp gdp_capita i.year"

glm level_share_l burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share_l burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share_l burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg sd_ahs_c_l burqual_ic_norm $controls mean_ahs_c_l, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" ) 
  
  
* fixed effects
set matsize 800
global controls "lngdp gdp_capita i.year"

glm level_share burqual_ic_norm $controls i.iso3n ,  nolog link(logit) family(binomial) robust 
estimates store m1

glm peak_share burqual_ic_norm $controls i.iso3n , nolog link(logit) family(binomial) robust 
estimates store m2

glm cut_share burqual_ic_norm $controls i.iso3n , nolog link(logit) family(binomial) robust 
estimates store m3


xtreg level_share burqual_ic_norm $controls , fe
estimates store m4

xtreg peak_share burqual_ic_norm $controls , fe
estimates store m5

xtreg cut_share burqual_ic_norm $controls , fe 
estimates store m6

estout m1 m2 m3 m4 m5 m6, extracols(4) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year *iso3n) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )
  
  
* NTBs
global controls "lngdp gdp_capita ntbs i.year "

glm level_share burqual_ic_norm $controls if WTOmem_MEM == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1
glm peak_share burqual_ic_norm $controls if WTOmem_MEM == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2
glm cut_share burqual_ic_norm $controls if WTOmem_MEM == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3
reg sd_ahs_c burqual_ic_norm $controls mean_ahs_c if WTOmem_MEM == 1, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(ntbs "NTB defendant" lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" ) 
  


* GATT/WTO disputes initiated
global controls "lngdp gdp_capita disputes i.year "

glm level_share burqual_ic_norm $controls if WTOmem_MEM == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1
glm peak_share burqual_ic_norm $controls if WTOmem_MEM == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2
glm cut_share burqual_ic_norm $controls if WTOmem_MEM == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3
reg sd_ahs_c burqual_ic_norm $controls mean_ahs_c if WTOmem_MEM == 1, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(disputes "GATT/WTO disputes initiated" lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" ) 
  

* STCs initiated
global controls "lngdp gdp_capita ntbs_complaints i.year "

glm level_share burqual_ic_norm $controls if WTOmem_MEM == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1
glm peak_share burqual_ic_norm $controls if WTOmem_MEM == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2
glm cut_share burqual_ic_norm $controls if WTOmem_MEM == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3
reg sd_ahs_c burqual_ic_norm $controls mean_ahs_c if WTOmem_MEM == 1, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(ntbs_complaints "STCs initiated" lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" ) 
  

* Freedom House data
global controls "lngdp gdp_capita e_fh_pr vdem_gcrrpt i.year "

glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg sd_ahs_c burqual_ic_norm $controls mean_ahs_c, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(e_fh_pr "Freedom House" lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" vdem_gcrrpt "Legislative corruption")

  
* CGV house data
global controls "lngdp gdp_capita democracy vdem_gcrrpt i.year "

glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg sd_ahs_c burqual_ic_norm $controls mean_ahs_c, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(democracy "CGV democracy" lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" vdem_gcrrpt "Legislative corruption")
 

* Continuous polity
global controls "lngdp gdp_capita polity2 vdem_gcrrpt i.year "

glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg sd_ahs_c burqual_ic_norm $controls mean_ahs_c, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(polity2 "Polity (continuous)" lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" vdem_gcrrpt "Legislative corruption")

 
* only middle- and high-income countries
global controls "lngdp gdp_capita i.year "

set more off
glm level_share burqual_ic_norm $controls if high == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

glm peak_share burqual_ic_norm $controls if high == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2

glm cut_share burqual_ic_norm $controls if high == 1, nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3

reg sd_ahs_c burqual_ic_norm $controls mean_ahs_c if high == 1, robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )
  
  
* WTO & PTAs
global controls "lngdp gdp_capita WTOmem sum_ptas i.year"

glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1
glm peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2
glm cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3
reg sd_ahs_c burqual_ic_norm mean_ahs_c $controls , robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(sum_ptas "PTAs" WTOmem "WTO member" lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )

  
* IMF program 
global controls "lngdp gdp_capita imf5 i.year if year <= 2011"

glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1
glm peak_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m2
glm cut_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m3
reg sd_ahs_c burqual_ic_norm mean_ahs_c $controls , robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(imf5 "IMF program" lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )



* country-wide average pooled
preserve
global controls "lngdp gdp_capita i.year"

qui glm level_share c.burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
drop if e(sample) != 1

foreach var in level_share cut_share peak_share sd_ahs_c mean_ahs_c burqual_ic_norm lngdp gdp_capita {
by iso3n, sort: egen avg_`var' = mean(`var')
}
keep iso3n avg_level_share avg_cut_share avg_peak_share avg_burqual_ic_norm avg_lngdp avg_gdp_capita avg_sd_ahs_c avg_mean_ahs_c
duplicates drop

glm avg_level_share avg_burqual_ic_norm avg_lngdp avg_gdp_capita , nolog link(logit) family(binomial) robust 
estimates store m1
glm avg_peak_share avg_burqual_ic_norm avg_lngdp avg_gdp_capita , nolog link(logit) family(binomial) robust 
estimates store m2
glm avg_cut_share avg_burqual_ic_norm avg_lngdp avg_gdp_capita , nolog link(logit) family(binomial) robust 
estimates store m3
reg avg_sd_ahs_c avg_burqual_ic_norm avg_lngdp avg_gdp_capita avg_mean_ahs_c , robust 
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(avg_burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N , fmt(0) labels("Number Obs." ))  ///
  nolz style(tex)  varlabels(avg_lngdp "GDP" avg_gdp_capita "GDP per capita" avg_burqual_ic_norm "Bureaucratic Capacity" ///
  avg_mean_ahs_c "Average tariff" _cons "Constant" )
restore 


* IV estimates
global controls "lngdp gdp_capita i.year"

ivregress 2sls level_share ( burqual_ic_norm = gender_gap) $controls , robust cluster(iso3n) 
estimates store m1
ivregress 2sls peak_share ( burqual_ic_norm = gender_gap) $controls , robust cluster(iso3n) 
estimates store m2
ivregress 2sls cut_share ( burqual_ic_norm = gender_gap) $controls , robust cluster(iso3n) 
estimates store m3
ivregress 2sls sd_ahs_c ( burqual_ic_norm = gender_gap) $controls mean_ahs_c, robust cluster(iso3n) 
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )


* apparel tariffs
use "country_year_apparel.dta", replace
global controls "lngdp gdp_capita i.year"

glm level_share burqual_ic_norm $controls , nolog link(logit) family(binomial) robust cluster(iso3n)
estimates store m1

use "country_year_product_apparel.dta", replace
global controls "lngdp gdp_capita i.year"

logit level burqual_ic_norm $controls, nolog robust cluster(iso3n)
estimates store m2
logit level burqual_ic_norm $controls i.counter, nolog robust cluster(iso3n)
estimates store m3
reg absdiff burqual_ic_norm $controls,  robust cluster(iso3n)
estimates store m4

estout m1 m2 m3 m4, extracols(4 ) order(burqual_ic_norm ) cells(b(star fmt(a2)) ///
  p(par fmt(%4.3f))) starlevels( * .1 ** .05 *** .01) stats(N N_clust, fmt(0) labels("Number Obs." "Number Countries"))  ///
  nolz style(tex)  drop(*year *counter) varlabels(lngdp "GDP" gdp_capita "GDP per capita" burqual_ic_norm "Bureaucratic Capacity" ///
  mean_ahs_c "Average tariff" _cons "Constant" )




